package callable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class CallableTest {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        FutureTask futureTask = new FutureTask(myThread);
        new Thread(futureTask).start();
        try {
            //get可能会产生阻塞
            String o = (String) futureTask.get();
            System.out.println(o);
        } catch (Exception e) {
            e.printStackTrace();
        }


        try {
            new MyThread().call();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
class MyThread implements Callable<String> {


    @Override
    public String call() throws Exception {
        System.out.println("call()");
        return "testCallable";
    }
}
